import com.mq.pojo.Blog;
import com.mq.service.BlogService;
import com.mq.service.BlogServiceImpl;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class test {

	@Autowired
	@Qualifier("BlogServiceImpl")
	private BlogService service;

@Test
	public void	alllist(){
		List<Blog> blogs = service.queryAllBLog();
		System.out.println(blogs);
	}


	public static SqlSessionFactory getSqlSessionFactory() {
		String resource = "mybatis-config.xml";
		InputStream inputStream = null;
		try {
			inputStream = Resources.getResourceAsStream(resource);
		} catch (IOException e) {
			e.printStackTrace();
		}

		SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

		return sqlSessionFactory;
	}

	@Test
	public void test2(){
		ApplicationContext ctx =
				new ClassPathXmlApplicationContext("applicationContext.xml");
		BlogServiceImpl bs=ctx.getBean(BlogServiceImpl.class);
		List<Blog> blogs = bs.queryAllBLog();
		System.out.println(blogs);
	}

}
